package com.petrooil.core.model;

import javax.persistence.*;
import java.io.Serializable;

import static javax.persistence.GenerationType.IDENTITY;

@Entity
@Table(name = "user_departments", catalog = "orbeon", uniqueConstraints = @UniqueConstraint(columnNames = { "department", "username" }))
public class UserDepartment implements Serializable{

	private Integer userDepartmentId;
	private User user;
	private String department;

	public UserDepartment() {}

	public UserDepartment(User user, String department) {
		this.user = user;
		this.department = department;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "user_department_id", unique = true, nullable = false)
	public Integer getUserDepartmentId() {
		return this.userDepartmentId;
	}

	public void setUserDepartmentId(Integer userDepartmentId) {
		this.userDepartmentId = userDepartmentId;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "username", nullable = false)
	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Column(name = "department", nullable = false, length = 50)
	public String getDepartment() {
		return this.department;
	}

	public void setDepartment(String department) {
		this.department = department;
	}

}